package Data::Timeline::SVK;

use strict;
use warnings;
use DateTime::Format::DateParse;


our $VERSION = '0.03';


use base qw(Data::Timeline::Builder);


__PACKAGE__->mk_scalar_accessors(qw(base_dir));


sub create {
    my $self = shift;

    my $timeline = $self->make_timeline;

    chdir $self->base_dir or
        die sprintf "can't chdir to %s: $!\n", $self->base_dir;

    open my $fh, '-|', "svk log" or die "can't read from pipe 'svk log': $!\n";
    while (<$fh>) {
        next unless /^(r\d+:\s*\w+)\s*\|\s*(20.*)/;
        $timeline->entries_push($self->make_entry(
            description => $1,
            timestamp   => DateTime::Format::DateParse->parse_datetime($2),
            type        => 'svk',
        ));
    }
    close $fh or die "can't close pipe to 'svk log': $!\n";
    $timeline;
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - Builds a timeline from an 'svk log'


=head1 SYNOPSIS

    my $svk_timeline = Data::Timeline::SVK->new(
        base_dir => $svk_base_dir
    )->create;

=head1 DESCRIPTION

This class parses the output of C<svk log> in a given directory and creates a
timeline with entries corresponding to commits. Only the revision number and
the committer name are recorded in the entry descriptions.

The timeline entries generated by this builder have the type C<svk>.

This class manually parses the output of C<svk log>; it would probably be
better to use classes provided by the L<SVK> distribution, but because of its
dependency on L<SVN::Core>, the L<SVK> distribution is a bit difficult to
install.

=head1 METHODS

=over 4

{% p.write_methods %}

=item base_dir

The directory from which the C<svk log> command is issued.

=item create

Start parsing the output of C<svk log> and return a L<Data::Timeline> object
with the commit information.

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

